<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="utf-8"%>
<%@ include file="/website/layout/tag.jsp"%>
<script type="text/javascript">
	$(document).ready( 
		function() {
			//事件注册.
			$("#saveBtn").click(saveUser);
			$("#returnBtn").click(returnToList);
			
			$(":radio[name='type']").each(
				function() {
					$(this).click(changeRoleCheckStat);
				}
			);
			
			//设置左菜单对应菜单CSS为选中状态.
			changeToActiveCss("menu_7010");
			
			//消息显示.
			var msg = '<c:out value="${msg}"/>';
			if (msg != "") {
				alert(msg);
			}
		}
	);
	
	function saveUser() {
		//表单校验
		var loginName = $.trim($("#loginName").val());
		if (loginName == "") {
			alert("用户名称不能为空.");
			$("#loginName").focus();
			return false;
		}
		
		var loginPwd = $.trim($("#loginPwd").val());
		if (loginPwd == "") {
			alert("密码不能为空.");
			$("#loginPwd").focus();
			return false;
		}
		
		var confirmPwd =  $.trim($("#confirmPwd").val());
		if (loginPwd != confirmPwd) {
			alert("两次输入的密码不一致.");
			$("#loginPwd").focus();
			return false;
		}
		
		if (!confirm("保存管理员信息吗?")) {
			return false;
		}
	
		var action = $("#editForm").attr("action");
		action += "?oper=" + '<c:out value="${oper}"/>';
		$("#editForm").attr("action", action);
		$("#editForm").submit();
	}
	
	function returnToList() {
		window.location.href='${pageContext.request.contextPath}/system/enterEmployeeList.action';
	}
	
	function changeRoleCheckStat() {
		var type = $(this).val();
		if (type == "0") {
			$("input:checkbox[name='checkRoles']").each(
				function() {
					$(this).attr("disabled", true);
					$(this).removeAttr("checked");
				}
			);
		} else {
			$("input:checkbox[name='checkRoles']").each(
				function() {
					$(this).removeAttr("disabled");
				}
			);
		}
	}
</script>

<div id="content_right">
	<div style="width:100%;height:35px;line-height:35px;text-align:left;background-color:#F5FAFA;font-weight:bold; ">系统管理 > 管理员 > 编辑管理员</div>
	<div>
		<div id="tabBar">
			<span class="curentTab">管理员信息</span>
		</div>
		<div class="buttons" style="float:right; ">
			<a id="saveBtn" href="#">
				<img src="../images/btn_apply.png" alt=""/> 
				保存
			</a>
			<a id="returnBtn" href="#">
				<img src="../images/btn_apply.png" alt=""/> 
				返回列表
			</a>
		</div>
	</div>
	<div id="editContainer">
		<form:form id="editForm" action="${pageContext.request.contextPath}/system/saveEmployee.action" commandName="employee">
		<form:hidden path="id"/>
		<div id="baseInfo" class="editPanel">
			<span class="title">基本信息</span>
			<div style="clear:both;"></div>
			<div style="float:left; width:100%;margin-left:10px;">
				<table class="infoTable">
					<tr>
						<th>用户账号：</th>
						<td><form:input path="loginName" size="20" maxlength="20"/></td>
					</tr>
					<tr>
						<th>密码：</th>
						<td><form:password path="loginPwd" showPassword="true" size="20" maxlength="20"/></td>
					</tr>
					<tr>
						<th>确认密码：</th>
						<td><input type="password" size="20" maxlength="20" " name="confirmPwd" id="confirmPwd" value="${employee.loginPwd}"/></td>
					</tr>
					<input type="hidden" name="pwd" value="${employee.loginPwd}"/>
				</table>
			</div>
			<div style="clear:both;"></div>
		</div>
		
		<div id="baseInfo" class="editPanel">
			<span class="title">角色权限</span>
			<div style="clear:both;"></div>
			<div style="float:left; width:100%;margin-left:10px;">
				<table class="infoTable">
					<tr>
						<th>类型：</th>
						<td><form:radiobutton id="type1" path="isSys" value="0"/><label for="type1">普通管理员</label>&nbsp;&nbsp;<form:radiobutton id="type2" path="isSys" value="1"/><label for="type2">超级管理员</label></td>
					</tr>
					<tr>
						<th>权限角色：</th>
						<td>
							<select id="rules" name="ruleId" style="width:200px; ">
								 <option value="">请选择角色名 </option>
					  			 <c:if test="${not empty ruleList}">
						 			<c:forEach items="${ruleList}" var="item" varStatus="status">
						  		       <option value="${item.itemValue}" >${item.itemLabel}</option>
						     		</c:forEach>
								 </c:if>
							</select>
						</td>
					</tr>
					<tr>
						<th>状态：</th>
						<td><form:radiobutton id="status1" path="enable" value="0"/><label for="status1">启用</label>&nbsp;&nbsp;<form:radiobutton id="status2" path="enable" value="1"/><label for="status2">禁用</label></td>
					</tr>
					<tr>
						<th>账号起始时间：</th>
						<td>
							<c:choose>
								<c:when test="${oper == 'new'}">
									<input type="text" id="accountExpiredGTTime" name="accountExpiredGTTime" style="width:80px"   onclick=" WdatePicker({maxDate:'#F{$dp.$D(\'accountExpiredLTTime\')}'})" jwcid="E0252" value="${accountExpiredGTTime }"/>
								</c:when>
								<c:when test="${oper == 'modify'}">
									<input type="text" id="accountExpiredGTTime" value="${accountExpiredGTTime }"  readonly="readonly" style="width:80px"/>
								</c:when>
							</c:choose>
							&nbsp;-&nbsp;
							<input type="text" id="accountExpiredLTTime" name="accountExpiredLTTime" style="width:80px"  onclick=" WdatePicker({minDate:'#F{$dp.$D(\'accountExpiredGTTime\')}'})" jwcid="E0252" value="${accountExpiredLTTime }"/>
							&nbsp;(YYYYMMDD)
						</td>
					</tr>
						<tr>
						<th>证书起始时间：</th>
						<td>
							<c:choose>
								<c:when test="${oper == 'new'}">
									<input type="text" id="credentialsExpiredGTTime" name="credentialsExpiredGTTime" style="width:80px"   onclick=" WdatePicker({maxDate:'#F{$dp.$D(\'credentialsExpiredLTTime\')}'})" jwcid="E0252" value="${credentialsExpiredGTTime }"/>
								</c:when>
								<c:when test="${oper == 'modify'}">
									<input type="text" id="credentialsExpiredGTTime" value="${credentialsExpiredGTTime }"  readonly="readonly" style="width:80px"/>
								</c:when>
							</c:choose>
							&nbsp;-&nbsp;
							<input type="text" id="credentialsExpiredLTTime" name="credentialsExpiredLTTime" style="width:80px"  onclick=" WdatePicker({minDate:'#F{$dp.$D(\'accountExpiredGTTime\')}'})" jwcid="E0252" value="${credentialsExpiredLTTime }"/>
							&nbsp;(YYYYMMDD)
						</td>
					</tr>
				</table>
			</div>
			<div style="clear:both;"></div>
		</div>
		
		<div id="baseInfo" class="editPanel">
			<span class="title">其他信息</span>
			<div style="clear:both;"></div>
			<div style="float:left; width:100%;margin-left:10px;">
				<c:choose>
					<c:when test="${not empty employee.information}">
						<div class="buttons"> 
							<a id="modifyBtn" href="#">
								<img src="../images/btn_apply.png" alt=""/> 
								编辑
							</a>
						</div>
					</c:when>
					<c:otherwise>
						<div class="buttons"> 
							<a id="newBtn" href="#">
								<img src="../images/btn_apply.png" alt=""/> 
								新增
							</a>
						</div>
					</c:otherwise>
				</c:choose>
				<table class="infoTable">
					<tr>
						<th>姓名：</th>
						<td>${employee.information.name }</td>
					</tr>
					<tr>
						<th>部门：</th>
						<td>${employee.information.name }</td>
					</tr>
					<tr>
						<th>性别：</th>
						<td>${employee.information.sex }</td>
					</tr>
				</table>
			</div>
			<div style="clear:both;"></div>
		</div>
	</form:form>
	</div>
</div>

